// represents a list of Buddies
class ConsLoBuddy implements ILoBuddy {

  Person first;
  ILoBuddy rest;
  
  ConsLoBuddy(Person first, ILoBuddy rest) {
    this.first = first;
    this.rest = rest;
  }
  
  public ILoBuddy add(Person p){
    return new ConsLoBuddy(p, this);
  }
  
  public boolean contains(Person th){
     return first.equalsp(th) || rest.contains(th);
  }
  
  public int compareCount(ILoBuddy that){
     if (that.contains(this.first))
       return 1 + this.rest.compareCount(that);
     else return this.rest.compareCount(that);
  }
    
  public boolean checkDistant(Person that){
    return this.checkDistantHelp(that, new MTLoBuddy());
  }
  
  public boolean checkDistantHelp(Person that, ILoBuddy seen){
    if(seen.contains(this.first))
      return this.rest.checkDistantHelp(that, seen);
    return this.first.equalsp(that) || 
           this.first.buddies.checkDistantHelp(that, seen.add(this.first)) || 
           this.rest.checkDistantHelp(that, seen.add(this.first)); 
  }
  
  public int partyCounter(ILoBuddy beenThere){
	  if(beenThere.contains(this.first))
		  return this.rest.partyCounter(beenThere);
	  else return 1 + this.first.buddies.partyCounter(new ConsLoBuddy(this.first, beenThere)) 
	              + this.rest.partyCounter(new ConsLoBuddy(this.first, beenThere));
  }
  
  public int partyCount(Person p){
	  return this.partyCounter(new ConsLoBuddy(p, new MTLoBuddy()));
  }
  
  
}